/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package facade;

import entity.Warehouse;
import java.util.ArrayList;
import java.util.List;
import java.util.Vector;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

/**
 *
 * @author Svetlana Shikhutskaya
 */
@Stateless
public class WarehouseFacade extends AbstractFacade<Warehouse> implements WarehouseFacadeLocal {

    @PersistenceContext(unitName = "Delta-ejbPU")
    private EntityManager em;

    @Override
    protected EntityManager getEntityManager() {
        return em;
    }

    public WarehouseFacade() {
        super(Warehouse.class);
    }

    @Override
    public List<Warehouse> findByName(String name, int firstResult, int maxResults) {

        return getEntityManager()
                .createNamedQuery("Warehouse.findByName", Warehouse.class)
                .setParameter("name", "%" + name + "%")
                .setFirstResult(firstResult)
                .setMaxResults(maxResults)
                .getResultList();
    }

    @Override
    public List<Warehouse> findRange(int firstResult, int maxResults) {
        return super.findRange(firstResult, maxResults);
    }

    @Override
    public int count() {
        return Integer.parseInt(getEntityManager().createNamedQuery("Warehouse.count").getSingleResult().toString());
    }
}
